﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using BestLifePOS_Core.DomainObjects;
using BestLifePOS_Core.Data.Core;
using BestLifePOS_Core.Exceptions.DataBase;
using System.Data;


namespace BestLifePOS_Core.Data.Commands
{
    class BestLifeGetApprovedPoDetailsByPoIdDataAction : BestLifeDataAction<List<Purchase_Order>>
    {

        private string GvPOId;
        public BestLifeGetApprovedPoDetailsByPoIdDataAction(string PPoId)
        {
            GvPOId = PPoId;
        }

        public override List<Purchase_Order> Body(SqlConnection PConn)
        {
            try
            {
                List<Purchase_Order> LvList = new List<Purchase_Order>();

                SqlCommand LvCommand = new SqlCommand();
                LvCommand.Connection = PConn;
                LvCommand.CommandType = CommandType.StoredProcedure;
                LvCommand.CommandText = "dbo.GetApprovedPODetails";
                LvCommand.Parameters.Add(new SqlParameter("@PoID", GvPOId));//when passing parameters to the SP

                SqlDataReader LvReader = LvCommand.ExecuteReader();
               
                while (LvReader.Read())
                {
                    Purchase_Order LvAPO = new Purchase_Order();
                    LvAPO.Po_Id = LvReader.GetValue(0).ToString();
                    LvAPO.PL_Id = LvReader.GetValue(1).ToString();
                    LvAPO.Description = LvReader.GetValue(2).ToString();
                    LvAPO.Qty = decimal.Parse(LvReader.GetValue(3).ToString());
                    LvAPO.status = LvReader.GetValue(4).ToString();


                    //LvSubCategory.Description = LvReader.GetValue(4).ToString();
                    //LvSubCategory.Status = LvReader.GetValue(5).ToString();

                    LvList.Add(LvAPO);
                }

                return LvList;
            }
            catch (BestlifeDatabaseException e)
            {
                throw new BestlifeDatabaseException(e);
            }
        }
    }
}
